<?php
namespace Admin\Controller;

use Common\Controller\AdminbaseController;

class MessageController extends AdminbaseController {
	

	
	function _initialize() {
		parent::_initialize();
		$this->db = D("Message");
	}
	
	function index(){



		$map["uid"]=UID;





		$count=$this->db->where($map)->count();
		$page = $this->page($count, 20);

		$list=$this->db->where($map)->limit($page->firstRow . ',' . $page->listRows)->order(array("inputtime"=>"DESC"))->select();



		$this->assign("Page",$page->show(""));

		$this->assign("list",$list);
		$this->display();
	}
	
	

	
	function show(){
		
		
		$id=  intval(I("get.id"));
		
		$this->db->where("id=$id")->save(array("read"=>1));


		$rs=$this->db->where("id=$id")->find();

		if($rs["uid"]!=UID){
			$this->error("无权限！");
		}

		if($rs["url"]){



			header('Location:'.$rs["url"].'');
		}
			

			
			$this->assign("_data",$rs);
			
			
			$this->display("");
		
	}




	function  ifnew(){

		$map["uid"]=UID;
		$map["read"]=0;
		$count=$this->db->where($map)->count();

		echo $count;





	}


	public function read() {
		$id = $_REQUEST[id];



		$r = $this->db->where(array("id" => $id,"uid"=>UID))->find();

		if ($r) {
//			$data[tui] = $r['tui'] ? 0 : 1;
//			$data[id]=$id;
			$result=  $this->_read($id);
			if ($result !== false) {

				//$this->add_log("推荐设计师",$_POST["id"]);

				$this->success("成功");

			} else {
				$this->error("推荐成功！");
			}
		} else {
			$this->error("不存在！");
		}
	}






	public function _read($id){

		$data=array(
			"id"=>$id,
			"read"=>1
		);



		return $this->db->save($data);






	}



	

	
	
}